package helper

import (
	"encoding/json"
	"strconv"
	"strings"
	"time"
	"yundian/internel/pkg/dingo/result"
	"yundian/internel/pkg/utils"
)

// 判断 是否为管理员帐号
func IsAdmin(isadmin uint8) bool {
	if isadmin == 1 {
		return true
	}
	return false
}

// 判断 是否为网站创建者
func IsAdministrator(userId int, username string) bool {
	if userId == 1 && username == "administrator" {
		return true
	}
	return false
}

// 创建actionData
func GenerateActionData(act string) string {
	if act == "" {
		return ""
	}
	actions := make([]string, 0)
	_ = json.Unmarshal([]byte(act), &actions)
	actionData := make(result.ActionList, 0)
	actionList := result.NewActionList()
	for _,lst := range actionList {
		if utils.Contains(actions, lst.Action) {
			actionData = append(actionData, lst)
		}
	}
	b,_ := json.Marshal(actionData)
	return string(b)
}

/**
* 数字转字符串
 */
func Int2Str(v []int) string {
	var str []string
	for _, i := range v {
		str = append(str, strconv.Itoa(i))
	}
	return strings.Join(str, ",")
}

func GetDayRangeTime(startTime, stopTime string) (args []string) {
	tm1, _ := time.Parse("2006-01-02", startTime)
	tm2, _ := time.Parse("2006-01-02", stopTime)
	sInt := tm1.Unix()
	eInt := tm2.Unix()
	for {
		sInt += 86400
		st := time.Unix(sInt, 0).Format("2006-01-02")
		args = append(args,st)
		if sInt > eInt {
			return
		}
	}
}

func CheckOpenidStatus(openid string) bool {
	// 15970111912 oH48945H45BbyiZ_kLinku05D6Q4 恶意用户(6笔订单5次) 83%
	// 13129877726 oH489421GZV-fpXWNhDMg35ebrLY 恶意用户(3笔订单3次) 100%
	// 15706465630 oH48949rQuK8O6WeeTwUllDdWrYY 临时关闭
	// 18700790747 oH48945cRCTUYD6AdxeColofZSKM 恶意用户(2笔订单2次) 100%
	// 1869471858 oH48940QEBRgNAGT3DLI49csRqZM 恶意用户(2笔订单2次) 100%
	// 15723770902 oH48944Nub7NvmUim_-GfDu7IAtA 恶意用户(2笔订单2次) 100%
	// 13319989992 oH48949aZwzAZj2e3QOHGuMOItmc 恶意用户(2笔订单2次) 100%
	// 13978996611 oH4894zkYpDqlnW-S0L-FqpUTxDc 恶意用户(2笔订单2次) 100%
	// 13567184570 oH48949SCIE7wApdd6IdozKd1CAE 恶意用户(2笔订单2次) 100%
	// 15070078727 oH48944RFcQSNGRYpv-wXxyHYXpo 重复投诉
	// 18806088958 oH4894w73ID4hqCRj13Nd6BmXAsY 测试用户
	// 17602184021 oH48949D164eA54uaPHamVPB_xpY 测试用户
	// 18289443339 oH48948vsw8CviNynmSCd7SK6fd0
	str := "oH48945H45BbyiZ_kLinku05D6Q4,oH489421GZV-fpXWNhDMg35ebrLY," +
		"oH48940QEBRgNAGT3DLI49csRqZM,oH48944Nub7NvmUim_-GfDu7IAtA," +
		"oH48944RFcQSNGRYpv-wXxyHYXpo,oH4894zkYpDqlnW-S0L-FqpUTxDc," +
		"oH48949SCIE7wApdd6IdozKd1CAE,oH4894xbWujEAusVcbvY5lvL_6T8," +
		"oH489441z8cBcxioSm9_eevQL8Oo,oH4894zaFlCTJG9M7QBB9fvldikE," +
		"oH48949rQuK8O6WeeTwUllDdWrYY,oH48948vsw8CviNynmSCd7SK6fd0," +
		"oH48944NOTx3ImZrg0xRZkOmHCCw,oH4894xWFKEeNcIU0lfYBQofDFJo," +
		"oH48940QX_wkgLw7zAiR1Yc6l-Cs,oH4894xtqu6uAcbzSSo3HbZma4II," +
		"oH48946x8IR9E8H5ZSA4gQ9oB8L8,oH48947GTR5DF-BQ7YFDo4M2k_C8," +
		"oH48943HiSeQAkAE5bWNwiW8gUto,oH489463qtmb72KQCmFFIXDSPokQ," +
		"oH489478aWODgE4fGgPAogrftmTk,oH48949kB-aqLsNgsrXha29_VNoA," +
		"oH48949SCIE7wApdd6IdozKd1CAE,oH489477hxGVJrGH1w3swB9tHvnk," +
		"oH48944kG1wrDPxRID7Mgz5X1JDg,oH4894ylZeFrfNWsA4XKXgZ64ipU," +
		"oH48942TQVtqUP1BZOdSLPMzrfws,oH48945ktl8S8VOLpQNSCJEasQ7g," +
		"oH4894_-DdsJgxRZyLC4xXn0mgOU,oH4894_LNymN702y3sg1AAL81skw," +
		"oH489458KutHPV5iz-AWgTCeiIpw,oH48948S_4wJ_IijVhHz0PQV5xPc," +
		"oH48946zvuPalqTgpmLx6wyTpWbM,oH489424_cfAsEkg9exlReXyFyno," +
		"oH48948vqcAPl3KC5Dq5XYlpnkJA,oH48949b1JOJYLIVEP381t5Ccts4," +
		"oH489499h_VIBMl1kOjzVlS05BBc,oH48942kg9nW84Nc4uVHbcsoHAMc," +
		"oH48940fN2TgQLeoMoC5dNxQK2A8,oH489445JD-uNaxM1Ob86EQWFkMo," +
		"oH4894xmuBNNTpXeW1ANy8DPcLiE,oH48940wIZwVVfnSaiMEeixqT2Mo," +
		"oH4894yRjVMcQfZZ21U759X0Wvzk,oH4894z6MLH5TVEB335w5UBSnW2I"

	splitStr := strings.Split(str, ",")

	mapStr := make(map[string]string)
	for _, s := range splitStr {
		mapStr[s] = "true"
	}

	if mapStr[openid] == "true" {
		return true
	} else {
		return false
	}
}

